using UnityEngine;
using UnityEngine.UI;

namespace Assets.Scripts.Entities
{
    internal class ChildHappinessIndicator : MonoBehaviour
    {
        [SerializeField] private Child _child;
        [SerializeField] private Slider _slider;

        private Vector3 _positionOffset;

        private void Start ()
        {
            _positionOffset = _child.transform.position - transform.position;
            transform.SetParent(null);
        }

        private void Update()
        {
            if (_child == null || _child.CurrentState == Child.State.Leaving)
            {
                gameObject.SetActive(false);
                Destroy(gameObject);
                return;
            }

            transform.position = _child.transform.position - _positionOffset;
            _slider.value = _child.Happiness;
        }
    }
}
